<?php

namespace app\http\middleware;
use app\common\exception\BaseException;
use app\api\model\User;
class Check
{
    public function handle($request, \Closure $next)
    {
        if($request->header('accesstoken')) {
            $article = new User();
            $data = $article->where('accesstoken', $request->header('accesstoken'))->find();
            if($data) {
                return $next($request);
            }else {
                throw new BaseException('accesstoken错误, 请重新登录');
            }
        } else {
            throw new BaseException('请先登录');
        }
    }
}